package com.junit;

import com.pojo.User;
import com.utils.jdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;

public class dbUtiltest {
    @Test
    public void t(){
        String str = "1111asda";
        String str1 = "1111asda";
        if(str.equals(str1)){
            System.out.println("eq");
        }
        if(str==str1){
            System.out.println("==");
        }
    }
    @Test
public void dbutil() throws SQLException {
        Class<User> user = User.class;
         Connection conn = jdbcUtils.getConnection();
         QueryRunner query = new QueryRunner();
        Object[] o = {"sun","123456","181@163.cpm"};
        String sql = "insert into t_user(`username`,`password`,`email`) values(?,?,?)";
//        String sql = "select * from t_user";
//       List<User> list =  query.query(conn,sql,new BeanListHandler<User>(user));
//        System.out.println(list);
//        try {
          Object obj =  query.query(conn,sql,new ScalarHandler(),o);
        System.out.println(obj);
//        } catch (SQLException throwables) {
//            throwables.printStackTrace();
//        }
    }
    /**
     * 对jdbc测试
     */
    @Test
    public void test(){
        for(int i =1;i<=20;i++) {
            Connection conn = jdbcUtils.getConnection();
            System.out.println(i + "---" + conn);
            jdbcUtils.close(conn);
        }
    }
}
